package stream;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

public class StreamTest1 {
    public static void main(String[] args) {
        List<String> names = new ArrayList<>();
        Collections.addAll(names, "张无忌", "张三丰", "孙悟空", "牛魔王", "紫霞");


        List<String> list = new ArrayList<>();
        for (String name : names) {
            if (name.startsWith("张") && name.length() == 3) {
                list.add(name);
            }
        }
        System.out.println(list);

         List<String> list1 = names.stream().filter(s -> s.startsWith("张") && s.length()==3).collect(Collectors.toList());
        System.out.println(list1);
    }
}
